package com.newasia.server.common.interceptor.page;

import lombok.Data;

import java.util.List;

/**
 * @author LiChong
 * @description 分页信息
 * @date 2020/5/28
 */

@Data
public class PageMess<E> {

    //是否开启分页
    private boolean HasPageFunction = false;
    //当前页
    private int pageNum;
    //每页的数量
    private int pageSize;
    //当前页的数量
    private int size;
    //总页数
    private int pages;
    //前一页
    private int prePage;
    //下一页
    private int nextPage;
    //总记录数
    protected long total;
    //结果集
    protected List<E> list;
    //是否为第一页
    private boolean isFirstPage = false;
    //是否为最后一页
    private boolean isLastPage = false;
    //是否有前一页
    private boolean hasPreviousPage = false;
    //是否有下一页
    private boolean hasNextPage = false;

    public PageMess(List<E> list){
        this.list = list;
        if(list instanceof PageParam){
            PageParam pageParam = (PageParam)list;
            HasPageFunction = true;
            this.pageNum = pageParam.getPageNum();
            this.pageSize = pageParam.getPageSize();
            this.size = pageParam.getPageSize();
            this.pages = pageParam.getPages();
            this.prePage = pageParam.getPageNum();
            this.nextPage = pageParam.getPageNum();
            this.total = pageParam.getTotal();
            this.isFirstPage = pageParam.isFirstPage();
            this.isLastPage = pageParam.isLastPage();
            this.hasPreviousPage = pageParam.isHasPreviousPage();
            this.hasNextPage = pageParam.isHasNextPage();
        } else {
            this.total = list.size();
        }
    }
}
